import pylab
import numpy
def f(p):
    return lambda x,y: ((x*x+y*y) % p) % 5

def genimg(p,sx,sy):
    return numpy.fromfunction(f(p),(sx,sy))

im=pylab.imshow(genimg(37,144,144),interpolation = 'nearest')
pylab.show()
